using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using Common.Shared.Design;

namespace Common.Shared.Xml.Wddx {
	[WddxRoot("struct")]
	public class WddxStructure : WddxDataTypeObject {
		private List<WddxVariable> _variables;

		
		public WddxStructure ( ) {
			this.Variables = new List<WddxVariable> ( );
		}

		[WddxElement("var")]
		public List<WddxVariable> Variables {
			get { return _variables; }
			set { _variables = value; }
		}

		public WddxDataTypeObject this[ string name ] {
			get {
				return this[ this.IndexOf ( name ) ];
			}
		}

		public WddxDataTypeObject this[ int index ] {
			get {
				return this.Variables[ index ].Value;
			}
		}

		public bool Contains ( string name ) {
			return IndexOf ( name ) >= 0;
		}

		public int IndexOf ( string name ) {
			for ( int i = 0; i < this.Variables.Count; i++ ) {
				WddxVariable var = this.Variables[ i ];
				if ( string.Compare ( var.Name, name, true ) == 0 ) {
					return i;
				}
			}
			return -1;
		}

	}
}
